package com.hyacinth.cloudnote.common.dto.result;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.hyacinth.cloudnote.common.exception.AppRuntimeException;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.http.HttpStatus;

import java.util.List;

/**
 * 列表数据返回结果
 */
@NoArgsConstructor
@Getter
@Setter
public class ListResultDTO<T> extends AbstractResultDTO {
    private static final long serialVersionUID = 8756487352760469154L;

    /**
     * 列表数据
     */
    @ApiModelProperty(value = "列表数据", position = 10)
    @JsonProperty(index = 10)
    protected List<T> data;

    protected ListResultDTO(final HttpStatus status) {
        super(status);
    }

    ///////////////////////////////////////
    // Builder
    ///////////////////////////////////////
    public static <T> ListResultDTO<T> success(final List<T> listData) {
        if (listData == null) {
            throw new AppRuntimeException("The formal parameter 'listData' cannot be null");
        }

        final ListResultDTO<T> result = new ListResultDTO<>(HttpStatus.OK);
        result.setData(listData);
        return result;
    }
}
